<?php
namespace Admin\Controller;
use Admin\Controller\AdminController;
use Think\Page;

class PicController extends AdminController {
	public function _initialize(){
        parent::_initialize();
    }
	
	 /**
     * 会员列表
     */
    public function index(){
		$list = M('Pic_text')->select();
		foreach($list as $k=>$v){
			if(strlen($v['picurl']) >= 30){
				$list[$k]['picurl'] = substr($v['picurl'],0,20).'...';
			}
			if(strlen($v['url']) >= 30){
				$list[$k]['url'] = substr($v['url'],0,20).'...';
			}
		}
		$this->assign('list',$list);
		$this->display();
    }
	
	public function edit(){
		$id = I('post.id');
		$data['title'] = I('post.title');
		$data['description'] = I('post.description');
		$data['picurl'] = I('post.picurl');
		$data['url'] = I('post.url');
		
		// if(empty($data['title'] || empty($data['picurl']) || empty($data['url']))){
			// $data['info'] = '请补全信息';
			// $this->ajaxReturn($data);
		// }
		if(empty($id)){
			$data['info'] = '状态异常，请刷新';
			$this->ajaxReturn($data);
		}
		
		$re = M('Pic_text')->where("id={$id}")->save($data);
		if($re){
			$data['status'] = 1;
			$data['info'] = '保存成功';
			$this->ajaxReturn($data);
		}else{
			$data['status'] = -1;
			$data['info'] = '保存失败';
			$this->ajaxReturn($data);
		}
	}
}
	
